package com.suray.wcs.web.system.controller;

import com.suray.basic.wcs.utils.LoggerUtil;
import com.suray.commin.annotation.Log;
import com.suray.commin.enmus.BusinessType;
import com.suray.wcs.service.hk.agv.HkAgvControlThread;
import com.suray.wcs.service.hk.agv.bean.HkAgvCallBack;
import com.suray.wcs.service.hk.agv.bean.HkNormalResponse;
import com.suray.wcs.service.util.WcsUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/suray")
public class HkAgvController {

    @ApiOperation(value = "任务接收")
    @PostMapping("/agv/agvCallbackService/agvCallback")
    @Log(title = "Agv任务执行通知", method = "任务执行通知", businessType = BusinessType.INSERT)
    public HkNormalResponse agvCallback(@RequestBody HkAgvCallBack callBack) {
        try {
            LoggerUtil.info("接收到Agv任务执行通知：" + callBack.toString(), this.getClass());

            HkNormalResponse response = new HkNormalResponse();

            if (HkAgvControlThread.hkAgv.agvCallBack(callBack)) {
                response.setCode("0");
                response.setMessage("");
                response.setReqCode(callBack.getReqCode());
            } else {
                response.setCode("1");
                response.setMessage("信息错误");
                response.setReqCode(callBack.getReqCode());
            }

            return response;
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            HkNormalResponse response = new HkNormalResponse();
            response.setCode("1");
            response.setMessage(e.getMessage());
            response.setReqCode(callBack.getReqCode());
            return response;
        }
    }
}
